"use strict";
cc._RF.push(module, '9221bEsbRFKoYKas0Rf4Beu', 'PropIcon');
// Script/PropIcon.js

"use strict";

// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
/**
 * 技能图标脚本
 */
cc.Class({
    extends: cc.Component,

    properties: {
        speedX: 0, //x方向速度
        speedY: 0, //y方向速度
        speed: 200, //速度
        radius: 60,
        //适配
        winwidth: null,
        winheight: null,
        propType: 0 //道具类型
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad: function onLoad() {
        this.scheduleOnce(function () {
            //10秒后开始闪烁
            this.node.runAction(cc.repeat(cc.sequence(cc.fadeTo(0.1, 0), cc.fadeTo(0.1, 255)), 5 / 0.1)); //cc.blink()方法有毛病
            this.scheduleOnce(function () {
                //5秒后销毁
                this.node.destroy();
            }, 5);
        }, 10);
    },
    start: function start() {
        //var winSize = cc.director.getWinSize();
        var winSize = cc.winSize;
        this.winwidth = winSize.width;
        this.winheight = winSize.height;
        //this.speedX = cc.random0To1()-1;
        //this.speedY = cc.random0To1()-1;
        this.speedX = Math.random() - 1;
        this.speedY = Math.random() - 1;
    },
    update: function update(dt) {
        var x = this.node.getPosition().x;
        var y = this.node.getPosition().y;
        x += this.speedX * this.speed * dt;
        y += this.speedY * this.speed * dt;
        /*if(x < this.radius){
        	this.speedX = Math.abs(this.speedX);
        }
        if(y < this.radius){
        	this.speedY = Math.abs(this.speedY);
        }
        if(x < this.winwidth - this.radius){
        	this.speedX = -Math.abs(this.speedX);
        }
        if(y < this.winheight - this.radius){
        	this.speedY = -Math.abs(this.speedY);
        }*/
        var winSize = cc.winSize;
        if (x < -winSize.width / 2) {
            this.speedX = Math.abs(this.speedX);
        }
        if (y < -winSize.height / 2) {
            this.speedY = Math.abs(this.speedY);
        }
        if (x > winSize.width / 2) {
            this.speedX = -Math.abs(this.speedX);
        }
        if (y > winSize.height / 2) {
            this.speedY = -Math.abs(this.speedY);
        }
        this.node.setPosition(x, y);
    }
});

cc._RF.pop();